const appId="wx26e8c47e5a0bd00e";
const secret="775cbb4987b86eaa8ca3a7223c629f17";
const axios = require('axios');

 
async function getSessionKey(code){
    try
    {
        const url=`https://api.weixin.qq.com/sns/jscode2session?appid=${appId}&secret=${secret}&js_code=${code}&grant_type=authorization_code`;
        let data= await axios.get(url);
        if(!data.data.session_key){
            console.dir(data.data);
            return null;
        }
        console.dir(data.data);
        return data.data;
    }
    catch(e){
        console.error(e);
        return null;
    }
}



async function getUserInfo(token,openid){
    const url = `https://api.weixin.qq.com/sns/userinfo?access_token=${token}&openid=${openid}&lang=zh_CN`;
    let data= await axios.get(url);
    if(data.data.errcode!==0){
        console.dir(data.data);
        return null;
    }
    console.dir(data.data);
    return data;
}


export default{
    getSessionKey,
    getUserInfo,
    appId
}